package com.guguju.ssms;
import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.StrictMode;
import android.text.TextUtils;

import com.blankj.utilcode.utils.SPUtils;
import com.guguju.ssms.constant.SPConstant;
import com.guguju.ssms.core.http.HttpLoader;


/**
 * Created by zhitian on 2022-5-14.
 */
public class Guguju  extends Application {


    /**
     * application context
     */
    public static Context applicationContext;
    /**
     * 用户ID
     */
    public static int USERID = 0;
    /**
     * 用户授权码
     */
    public static String AUTH = "";
    /**
     * token
     */
    public static String ASESSTOKEN = "";

    /**
     * 安装渠道(string)
     */
    public static String setupChannel;

    /**
     * 已经打开loginActivity
     */
    public static boolean isOpenLoginActivity = false;


    @Override
    public void onCreate() {
        super.onCreate();
        applicationContext = getApplicationContext();

        initSomeparam();


        //网络请求初始化
       HttpLoader.init(this);

        strictMode();
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
       // MultiDex.install(this);
    }
    /**
     * 获取一些全局的参数
     */
    private void initSomeparam() {
       SPUtils schemeSp = new SPUtils(this, SPConstant.SP_XML_NAME);
        USERID = schemeSp.getInt(SPConstant.USERID);
        AUTH = schemeSp.getString(SPConstant.AUTH);
        ASESSTOKEN = schemeSp.getString(SPConstant.ASESSTOKEN);
        //getMobileSN();
        getSetupChannel();
    }



    //严苛模式
    private void strictMode() {
        if (BuildConfig.DEBUG) {
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                    .detectAll()
                    .penaltyLog()
                    .build());
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectAll()
                    .penaltyLog()
                    .build());
        }
    }


    /**
     * 安装渠道
     *
     * @return
     */
    public String getSetupChannel() {
        ApplicationInfo ai = null;
        try {
            ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        if (ai != null) {
            Bundle b = ai.metaData;
            if (b != null) {
                setupChannel = b.getString("UMENG_CHANEL");
            }
        } else {
            setupChannel = "Guguju_Com";
        }
        return setupChannel;
    }
}
